import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
// 评论粘的
const SET_COMMENT_LIST = 'setCommentList'
const INCREMENT = 'increment'
const DECREMENT = 'decrement'

export default new Vuex.Store({
  state: {
    username: '',
    name: '',
    userKey: '',
    chapterData: {}, //小节数据
    CSdata: {}, //章节数据
    commentList: [], //评论列表
    id: 100, //评论的
    ExampleKey: null, //算例key
    ExampleData: [], //算例数据
    isCheck: 1, // 1是课程资料 2是算例
    whichModule: 0, //0是课程学习模块，1是作业管理模块
    homeworkData: null, //发布作业menu的数据
    homeworkManageMenuData: {}, //作业管理menu点击后作业的数据
    JudgeHomeworkCode: {}, //评判作业里学生代码数据
  },
  mutations: {
    saveUserName(state, username) {
      state.username = username
    },
    saveName(state, name) {
      state.name = name
    },
    saveUserKey(state, userKey) {
      state.userKey = userKey
    },
    savaChapterData(state, chapterData) {
      state.chapterData = chapterData
    },
    saveCSdata(state, CSdata) {
      state.CSdata = CSdata
    },
    saveExampleKey(state, ExampleKey) {
      state.ExampleKey = ExampleKey
    },
    saveHomeworkManageMenuData(state, homeworkManageMenuData) {
      state.homeworkManageMenuData = homeworkManageMenuData
    },
    saveExampleData(state, ExampleData) {
      state.ExampleData = ExampleData
    },
    // 评论粘的
    [SET_COMMENT_LIST](state, commentList) {
      state.commentList = commentList
    },
    [INCREMENT](state) {
      state.id += 1
    },
    saveWhichModule(state, whichModule) {
      state.whichModule = whichModule
    },
    saveHomeworkData(state, data) {
      state.homeworkData = data
    },
    saveisCheck(state, data) {
      state.isCheck = data
    },
    saveJudgeHomeworkCode(state, data) {
      state.JudgeHomeworkCode = data
    },
  },
  actions: {
    saveUserName(context, username) {
      context.commit('saveUserName', username)
    },
    saveName(context, name) {
      context.commit('saveName', name)
    },
    saveUserKey(context, userKey) {
      context.commit('saveUserKey', userKey)
    },
    savaChapterData(context, chapterData) {
      context.commit('savaChapterData', chapterData)
    },
    saveCSdata(context, CSdata) {
      context.commit('saveCSdata', CSdata)
    },
    saveExampleKey(context, ExampleKey) {
      context.commit('saveExampleKey', ExampleKey)
    },
    saveExampleData(context, ExampleData) {
      context.commit('saveExampleData', ExampleData)
    },
    saveWhichModule(context, whichModule) {
      context.commit('saveWhichModule', whichModule)
    },
    saveHomeworkData(context, data) {
      context.commit('saveHomeworkData', data)
    },
    saveHomeworkManageMenuData(context, data) {
      context.commit('saveHomeworkManageMenuData', data)
    },
    saveisCheck(context, data) {
      context.commit('saveisCheck', data)
    },
    saveJudgeHomeworkCode(context, data) {
      context.commit('saveJudgeHomeworkCode', data)
    },
  },
  modules: {},
})
